<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@page import="org.osgi.framework.Bundle"%>
<%@page import="edu.ccut.saturn.core.impl.HostActivator"%>
<%
	String key = (String)request.getParameter("key");

	HostActivator activator = HostActivator.getInstance();
	Bundle[] bundles = activator.getBundleContext().getBundles();

	for (Bundle bundle : bundles) {
		if (bundle.getSymbolicName().equals(key)) {
			request.setAttribute("bundle",bundle);
		}
	}
		
	Bundle bundle = (Bundle) request.getAttribute("bundle");
	String symbolicName = bundle.getSymbolicName();
%>
<html>
<head>
<%@ include file="/extjs/include/all.jsp"%>
</head>
<body>
<div id="bundleTree" style="height: 100%"></div>

<script type="text/javascript">
	//单击事件
	function tonclick(id){ 
		if(id.indexOf(".")>-1){
		    //判断是组件还是数据项
		    var type = id.split(".")[1];
		    if(type == "saturnData"){
		        var param = "fullKey=http://<%=symbolicName%>/"+id.split(".")[0];
		        param = param.substring(0, param.lastIndexOf("/"))+"::"+ param.substring(param.lastIndexOf("/")+1,param.length);
		        //数据项验证的验证
		        //action = "<%=request.getContextPath()%>/edu.ccut.saturn.manager.bundles.impl::/extComponentModule/tdValidateAction/QuerySaturnDataInfoByFullKey.action?"+param;
		        action = "<%=request.getContextPath()%>/edu.ccut.saturn.manager.bundles.impl/extComponentModule/tdValidatePage/dataItemInfoList.jsp?"+param;
		        document.getElementById('ComponentInfo').src = action;
		    }else if (type == "component"){
		        var param = "fullKey=<%=symbolicName%>"+"::/"+id;
		        action = "<%=request.getContextPath()%>/edu.ccut.saturn.manager.bundles.impl/extComponentModule/page/basecomponentInfo.jsp?"+param;
		        document.getElementById('ComponentInfo').src = action;
		    }else{
			    var param = "fullKey=<%=symbolicName%>"+"::/"+id;
				action = "<%=request.getContextPath()%>/edu.ccut.saturn.manager.bundles.impl/extComponentModule/page/componentInfo.jsp?"+param;		
				document.getElementById('ComponentInfo').src = action;
		    }
		}
	}

	Ext.onReady(function(){
	
		var height = Ext.get('bundleTree').getHeight()-26;
		var saturnTree = new Ext.tree.TreePanel({
			title:'<%=key%>',
			id:'saturn-tree',//设置一个id
			autoScroll:true,//自动出现滚动条
			enableDD:false,//是否支持拖拽效果
			containerScroll: true,//是否支持滚动条
			rootVisible:true,//是否显示跟节点
			height:height,
			tools:[{
				id:'left',//根据id的不同会出现不同的按钮
				handler:function(){
		 window.location = '${pageContext.request.contextPath}/edu.ccut.saturn.manager.bundles.impl/extBundleModule/page/bundleManagemenetPage.jsp?';
					}
				}
			],
			loader:new Ext.tree.TreeLoader({
				dataUrl:'<%=request.getContextPath()%>/edu.ccut.saturn.manager.bundles.impl::/extComponentModule/action/GetJsonComponentTree.action?key=edu.ccut.saturn.manager.bundles.impl',
				clearOnLoad:false
			})
		});
		
		var treeRootNode = new Ext.tree.AsyncTreeNode({
			text:'src',
			id:'<%=key%>',
			icon:'images/src.gif'
		});
		
		saturnTree.setRootNode(treeRootNode);
		
		saturnTree.on('click', function(node) {
				if(!node.isLeaf()){   
		            return false;   
		        }
				tonclick(node.id)
		}, this);

		   //响应事件，传递node参数
   		saturnTree.on('beforeload', function(node){
            	if(node.id == '<%=key%>'){
               			saturnTree.loader.dataUrl='<%=request.getContextPath()%>/edu.ccut.saturn.manager.bundles.impl::/extComponentModule/action/GetJsonComponentTree.action?key='+node.id;    //定义子节点的Loader   
          		} else {		 
          		   		saturnTree.loader.dataUrl='<%=request.getContextPath()%>/edu.ccut.saturn.manager.bundles.impl::/extComponentModule/action/GetJsonComponentChildTree.action?key=<%=key%>&treeId='+node.id;    //定义子节点的Loader  	
          		} 
         }); 
                  
		 var bundleInfoView = new Ext.Viewport({
			layout:'border',
			items:[{
					region:'west',
					id:'west',
					title:'bundle',
					split:true,
					width: 200,
					minSize: 175,
					maxSize: 400,
					collapsible: true,
					margins:'0 0 0 2',
					collapsed:false,
					layoutConfig:{
						animate:true
					},
					items:saturnTree
				},{
					region:'center',
					id:'center',
					split:true,
					collapsed:false,
					layoutConfig:{
						animate:true
					},
					items: [{html:'<iframe id="ComponentInfo" name="ComponentInfo" width="100%" marginwidth="0" height="'+height+'px" marginheight="0" scrolling="auto" frameborder="0"></iframe>'}]
				}
			]
		});
	});
</script>
</body>
</html>